package com.technology.education.ui.student.evaluate

import androidx.lifecycle.MutableLiveData
import com.huantansheng.easyphotos.models.album.entity.Photo
import com.technology.education.ext.toast
import com.technology.education.network.apiService
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.state.ResultState
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File

/**
 *@author:create by BZY
 *Date: 2022/3/22 08
 */
class EvaluateViewModel : BaseViewModel() {
    /**
     * 评价结果 1非常满意 0不太满意
     */
    var commentResult = 1
    var selectedTags = mutableListOf<String>()

    /**
     * 选择的照片
     */
    var selectedPhotos = mutableListOf<Photo>()
    val tagList = MutableLiveData<ResultState<List<String>>>()
    val result = MutableLiveData<Boolean>()
    var commentContent = ""
    var orderId = ""

    override fun getData() {
        super.getData()
        request({ apiService.commentTagList() }, tagList)
    }

    fun commitData() {
        if (commentContent.isEmpty()) {
            toast("请输入您的评价")
            return
        }
        request(
            {
                apiService.commentTeachOrder(
                    hashMapOf(
                        "commentContent" to commentContent,
                        "commentResult" to commentResult,
                        "commentTags" to selectedTags,
                        "id" to orderId
                    )
                )
            },
            success = {
                result.postValue(true)
            },
            error = {
                toast(it.errorMsg)
            },
            isShowDialog = true
        )
    }
}